#!/bin/sh
export DEBIAN_FRONTEND=none
. /usr/share/debconf/confmodule
bootif=`sed 's/.*BOOTIF=\([-a-z0-9]*\).*/\1/; t; d' /proc/cmdline`
if [ "$bootif" ]; then
    interface_found=""
    # bootif is 01-00-19-b9-e1-c6-94, convert to MAC
    mac=${bootif#01-}
    mac=`echo $mac | sed 's/-/:/g'`
    log-output -t ethdetect echo "Found bootif $bootif, looking for MAC $mac"
    cd /sys/class/net
    for interface in *; do
	if [ `cat $interface/address` = "$mac" ]; then
	    log-output -t ethdetect echo "Found matching interface $interface"
	    interface_found=$interface
	    db_set netcfg/choose_interface $interface
            # must mark question as seen otherwise you are reprompted
	    db_fset netcfg/choose_interface seen true
	fi
    done
    if [ ! "$interface_found" ]; then
	log-output -t ethdetect echo "No matching interface for MAC $mac"
    fi
fi